<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/layuiadmin/style/admin.css" media="all">
    <style>
        .layui-btn-container {
            font-size: 14px;
        }
    </style>
</head>

<body layadmin-themealias="default">

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body" pad15="">

                    <div class="layui-form" wid100="" lay-filter="">
                        <input type="hidden" name="type" value="{$type}">
                        <div class="layui-form-item">
                            <div class="layui-input-inline layui-btn-container" style="width: auto;">
                                <button type="button" class="layui-btn layui-btn-primary" id="excelUpload">上传Excel文件</button>
                                <button class="layui-btn layui-btn-primary" id="download">模板下载</button>
                            </div>
                        </div>
                        <!--<div class="layui-form-item">-->
                        <!--    <label class="layui-form-label">禁用该设备使用过的账号</label>-->
                        <!--    <div class="layui-input-block">-->
                        <!--        <input type="checkbox" lay-skin="switch" lay-text="开启|关闭" lay-filter="switch_shortvideo_check">-->
                        <!--    </div>-->
                        <!--</div>-->
                        <div class="layui-form-item">
                            <p>上传结果:总计<b class="totalUpload">0</b>条，上传成功<b class="successUpload">0</b>条，重复<b class="duplicateUpload">0</b>条</p>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block text-center">
                                <button class="layui-btn" lay-submit="" id="startUploadFile">开始上传</button>
                                <button class="layui-btn layui-btn-primary" id="close">取消</button>
                            </div>
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>

<script src="/layuiadmin/layui/layui.js"></script>
<script src="/assets/cos-js-sdk-v5/cos-js-sdk-v5.min.js"></script>
<script>
    layui.config({
        base: '/layuiadmin/'
        , version: "{:config('other.ui_version')}"
    }).extend({
        index: 'lib/index', //主入口模块
        excel: 'excel',
    }).use(['index', 'form', 'admin', 'black', 'upload','excel'], function () {
        var $ = layui.$
            , form = layui.form
            , upload = layui.upload
            , admin = layui.admin;
        var index = parent.layer.getFrameIndex(window.name);

        $('#download').on("click", function () {
            layui.excel.exportExcel([['值', '备注']], '模板.xlsx', 'xlsx')
        });

        $('#close').on("click", function () {
            parent.layer.close(index);
        });

        //选完文件后不自动上传
        upload.render({
            elem: '#excelUpload'
            , url: '{:url("security/import_file")}?type={$type}' //此处配置你自己的上传接口即可
            , auto: false
            , accept: 'file' //普通文件
            , exts: 'xls|xlsx' //只允许上传压缩文件
            , multiple: true
            , bindAction: '#startUploadFile'
            , done: function (res) {
                if(res.code==0){
                    $('.totalUpload').text(res.data.total);
                    $('.successUpload').text(res.data.success);
                    $('.duplicateUpload').text(res.data.duplicate);
                    layer.msg('上传成功',function(){
                        parent.layer.close(parent.layer.getFrameIndex(window.name));
                        parent.layui.table.reload('LAY-ads-svideo-manage');
                    });

                }else{
                    layer.msg(res.msg, {icon: 5});
                }
                console.log(res)
            }
        });

    });
</script>
</body>
</html>
